<?php
namespace news\Controller;
use Common\Controller\BehaviorController;
use Common\Model\NewsModel;
use Common\Model\NewsCategoryModel;

class CommonController extends BehaviorController {

    public function getCategoryByPid(){
        $categoryModel = new NewsCategoryModel();
        $category = $categoryModel->getCategoryGroPid();
        $cid = array_column($category,'category','id');
        $pid = array_column($category,'category','pid');
        $temp = array();
        foreach($category as $k => $v){
            $temp[$v['pid']][] = $v;
        }
        $data = array(
            'cid' => $cid,
            'pid' => $pid,
            'data'=> $temp
        );
        return $data;
    }

    public function getInfoCategory($cid, $pid)
    {
        $categoryModel = new NewsCategoryModel();
        if (empty($pid)) {
            $category = $categoryModel->getCategoryById($cid);
        } else {
            $category = $categoryModel->getCategoryByPid($pid);
        }
        return $category;
    }

    public function getFatherCategory($cid)
    {
        $categoryModel = new NewsCategoryModel();
        $category = $categoryModel->getFatherCategory($cid);
        $father = $categoryModel->getCategoryById($category['pid']);
        $data = array(
            'current' => $category,
            'father' => $father,
        );
        return $data;
    }

    public function getInfoInId($idArr)
    {
        $info = new NewsModel();
        $data = $info->getInfoInId($idArr);
        return $data;
    }

}